﻿/**
 * 
 * @param {url，type，data ，method} 对象
 */

var request = function ({ url, type, data, asyn, hrefurl, success, error }) {
    var async = asyn || false;
    hrefurl = hrefurl || '/Login/Index';
    type = type || 'POST';
    data = data || {};
    $.ajax({
        url: url,
        method: type,
        async: async,
        data: data,
        success: function (data) {
            if (data.code == 401) {
                window.location.href = '/Login/Index';
                return false;
            }
            if (success) {
                success(data);
            }
        },
        error: function (info) {
            redirectLogin(info);
        }
    })
}

var redirectLogin = function (data) {
    if (data == 401 || (data.status || data.status==401)) {
        alert("登录已过期，请重新登录！")
        window.location.href = '/Login/Index';
    }
}

//验证手机号是否正确
var validatePhone = function (val) {
    if (!(/^1(3|5|6|7|8|9)\d{9}$/.test(val))) {
        return false;
    }
    return true;
}